import java.awt.FlowLayout;
import java.util.Iterator;

import javax.swing.*;;


public class MainFrame extends JFrame {

	// Panel
	private JPanel panel;

	// List
	private JList<StreamCopyThread> list;
	private JScrollPane scrollList;

	//JLabel
	private JLabel statusImg;
	
	//Images
	private ImageIcon statusStart;
	private ImageIcon statusStop;
	
	//Actions
	private RunAction startAction;
	private StopAction stopAction;
	
	// Button
	private JButton bRun;
	private JButton bRefresh;

	public MainFrame()
	{
		super();
		initialize();
	}

	private void initialize()
	{
		// Panel
		this.panel = new JPanel();
		panel.setLayout(new FlowLayout());

		// List
		list = new JList<StreamCopyThread>();
		list.setLayoutOrientation(JList.VERTICAL);
		list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
		scrollList = new JScrollPane(list);
		scrollList.setSize(50, 100);
		panel.add(scrollList);

		// Images
		statusStart = new ImageIcon("images/ok.gif");
		statusStop = new ImageIcon("images/notok.gif");
		
		// JLabel
		statusImg = new JLabel();
		panel.add(statusImg);
		
		//Actions
		this.startAction = new RunAction(this);
		this.stopAction = new StopAction(this);
		
		// Button
		this.bRun = new JButton();
		panel.add(bRun);
		this.bRefresh = new JButton(new RefreshAction(this));
		bRefresh.setText("Refresh");
		panel.add(bRefresh);
		
		setStatusStop();
		setTitle("MPA - Minecraft Protocol Analyzer");
		setSize(800,600);
		setLocationRelativeTo(null);
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setContentPane(panel);
		setVisible(true);

	}
	
	public void setStatusStart()
	{
		statusImg.setIcon(statusStart);
		bRun.setAction(stopAction);
		bRun.setText("Stop proxy");
	}
	
	public void setStatusStop()
	{
		statusImg.setIcon(statusStop);
		bRun.setAction(startAction);
		bRun.setText("Start proxy");
	}

	public void refreshList()
	{
		list.setListData(Controler.instance().getConnections());

	}

}
